<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title>Document</title>
  <style>
    
  </style>
</head>
<body>
  <div class="form">
    用户名：<input type="text" class="un"><br>
    密码：<input type="text" class="pw"><br>
    手机号：<input type="text" class="tel"><br>
    邮箱：<input type="text" class="email"><br>
    权限：<select class="power">
      <option value="0">超级管理员</option>
      <option value="1">普通管理员</option>
      <option value="2">用户</option>
      <option value="3">游客</option>
    </select><br>
    VIP：<input type="checkbox" class="isVIP"><br>
    爱好：<input type="input" class="hobby"><span>每个爱好之间使用逗号隔开</span><br>
    <input type="button" class="btn" value="提交">
  </div>
</body>
<script src="./ajax.js"></script>
<script>

  $(".btn").onclick = function(){

    ajax({
      url: "http://localhost:3000/adduser",
      method:"post",
      data:{
        username: $(".un").value,
        password: $(".pw").value,
        tel: $(".tel").value,
        email: $(".email").value,
        power: $(".power").value,
        isVIP: Number($(".isVIP").checked),
        hobby: JSON.stringify($(".hobby").value.split(/,|，/)),
      }
    }).then(res=>{
      console.log(res);
    })

  }

  
  function $(s){
    return document.querySelector(s);
  }


</script>
</html>